package com.joe.utils;

import java.util.Arrays;

/**
 * Created by joe on 2018/11/25
 */
public class PathUtils {

    private static final ClassLoader CLASS_LOADER = PathUtils.class.getClassLoader();

    /**
     * 获得运行时资源路径
     */
    public static String getRuntimeResourcePath() {
        return CLASS_LOADER.getResource("").getPath();
    }

    /**
     * 获得 File 的文件目录数组
     */
    public static String[] pathSplit(String path) {
        String[] strings = path.trim().split("[\\\\/]");
        if (strings.length > 0 && strings[0].length() == 0) {
            return Arrays.copyOfRange(strings, 1, strings.length);
        }
        return strings;
    }

    /**
     * 获得 path 中最后一个目录
     */
    public static String getLastDir(String path) {
        String[] pathArr = pathSplit(path);
        if (!ArrayUtils.isEmpty(pathArr)) {
            return pathArr[pathArr.length - 1];
        }
        return "";
    }

}
